package com.lr.api.controller.v1;

import com.lr.domain.entity.Jobs;
import com.lr.service.JobsService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/jobs")
public class JobsController {

    private JobsService jobsService;

    public JobsController(JobsService jobsService) {
        this.jobsService = jobsService;
    }
//  查询
    @GetMapping("/findJobs")
    public ResponseEntity<?> getJobs(){
        List<Jobs> jobs = jobsService.findJobs();
        return ResponseEntity.ok(jobs);
    }
//  添加
    @PostMapping("/createJob")
    public ResponseEntity<?> createJob(Jobs jobs){
        jobsService.createJob(jobs);
        return ResponseEntity.ok(jobs);
    }
//  删除
    @DeleteMapping("/deleteJob/{id}")
    public ResponseEntity<?> deleteJob(@PathVariable("id") String id){
        jobsService.deleteJob(id);
        return ResponseEntity.ok("删除成功！");
    }

//    更新
    @PutMapping("/updateJob")
    public ResponseEntity<?> updateJob(Jobs jobs){
        jobsService.updateJob(jobs);
        return ResponseEntity.ok(jobs);
    }
//    组合插入
    @PostMapping("/updateJobAnd")
    public ResponseEntity<?> updateJobAnd(List<Jobs> jobs){
        jobsService.insertBatch(jobs);
        return ResponseEntity.ok(jobs);
    }
}
